﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Vit.Web.Mvc
{
    public class DataAnnotationsModelMetadataProvider2 : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
        {
            ModelMetadata meta = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            meta.IsRequired = attributes.Where(x => x is RequiredAttribute).Count() > 0;
            return meta;
        }
    }
}
